<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <div v-if="crud.props.searchToggle">
        <!-- 搜索 -->
        <label class="el-form-item-label">{{ $t('processcard.processcardCode') }}</label>
        <el-input v-model="query.processcardCode" clearable :placeholder="$t('processcard.processcardCode')" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <label class="el-form-item-label">{{ $t('processcard.workNum') }}</label>
        <el-input v-model="query.workNum" clearable :placeholder="$t('processcard.workNum')" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <label class="el-form-item-label">{{ $t('processcard.productType') }}</label>
        <el-input v-model="query.productType" clearable :placeholder="$t('processcard.productType')" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <rrOperation :crud="crud" />
      </div>
      <!--如果想在工具栏加入更多按钮，可以使用插槽方式， slot = 'left' or 'right'-->
      <crudOperation :permission="permission" />
      <!--表格渲染-->
      <el-table ref="table" v-loading="crud.loading" :data="crud.data" size="small" style="width: 100%;" @selection-change="crud.selectionChangeHandler">
        <el-table-column type="selection" width="55" />
        <el-table-column prop="id" :label="$t('processcard.id')" />
        <el-table-column prop="processcardCode" :label="$t('processcard.processcardCode')" />
        <el-table-column prop="workNum" :label="$t('processcard.workNum')" />
        <el-table-column prop="productType" :label="$t('processcard.productType')" />
        <el-table-column prop="material" :label="$t('processcard.material')" />
        <el-table-column prop="thick" :label="$t('processcard.thick')" />
        <el-table-column prop="size1" :label="$t('processcard.size1')" />
        <el-table-column prop="size2" :label="$t('processcard.size2')" />
        <el-table-column prop="layerName" :label="$t('processcard.layerName')" />
        <el-table-column v-if="checkPer(['admin','processcard:edit','processcard:del'])" :label="$t('common.operation')" width="150px" align="center">
          <template slot-scope="scope">
            <udOperation
              :data="scope.row"
              :permission="permission"
            />
          </template>
        </el-table-column>
      </el-table>
      <!--分页组件-->
      <pagination />
    </div>
  </div>
</template>

<script>
import crudProcesscard from '@/api/processcard'
import CRUD, { presenter, header, form, crud } from '@crud/crud'
import rrOperation from '@crud/RR.operation'
import crudOperation from '@crud/CRUD.operation'
import udOperation from '@crud/UD.operation'
import pagination from '@crud/Pagination'

const defaultForm = { id: null, processcardCode: null, workNum: null, productType: null, material: null, thick: null, size1: null, size2: null, layerName: null }
export default {
  name: 'Processcard',
  components: { pagination, crudOperation, rrOperation, udOperation },
  mixins: [presenter(), header(), form(defaultForm), crud()],
  cruds() {
    return CRUD({ title: '工艺卡', url: 'api/processcard', idField: 'id', sort: 'id,desc', crudMethod: { ...crudProcesscard }})
  },
  data() {
    return {
      permission: {
        add: ['admin', 'processcard:add'],
        edit: ['admin', 'processcard:edit'],
        del: ['admin', 'processcard:del']
      },
      rules: {
      },
      queryTypeOptions: [
        { key: 'processcardCode', display_name: '工艺卡编码' },
        { key: 'workNum', display_name: '工程号' },
        { key: 'productType', display_name: '产品类型' }
      ]
    }
  },
  methods: {
    // 钩子：在获取表格数据之前执行，false 则代表不获取数据
    [CRUD.HOOK.beforeRefresh]() {
      return true
    }
  }
}
</script>

<style scoped>

</style>
